package com.fhz.day004;

import android.content.Context;
import android.util.Log;

import androidx.annotation.NonNull;
import androidx.work.Data;
import androidx.work.Worker;
import androidx.work.WorkerParameters;

/**
 * 时间:2022/3/23
 *
 * @author msfeng
 * 简述: TODO
 */
public class MyWork extends Worker {
    private static final String TAG = "work";
    private static final String PROGRESS = "PROGRESS";
    private static final long DELAY = 1000L;
    public MyWork(@NonNull Context context, @NonNull WorkerParameters workerParams) {
        super(context, workerParams);
        setProgressAsync(new Data.Builder().putInt(PROGRESS, 0).build());
    }

    @NonNull
    @Override
    public Result doWork() {

        Log.i(TAG, "doWork: ");
        //下载.
        String name = getInputData().getString("name");
//        if(name == null){
//            return Result.failure();
//        }

        //下载
//        if(true){
//            return Result.success();
//        }
        setProgressAsync(new Data.Builder().putInt(PROGRESS, 100).build());
        return Result.success(new Data.Builder().putInt(PROGRESS, 100).build());
    }
}

